package com.coolbi.onsupai.core.biz.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.biz.GoodsCategoryBiz;
import com.coolbi.onsupai.core.dao.GoodsCategoryDao;
import com.coolbi.onsupai.core.entity.GoodsCategory;
import com.coolbi.onsupai.core.exception.ServiceException;

public class GoodsCategoryBizImpl implements GoodsCategoryBiz {

	@Autowired
	private GoodsCategoryDao goodsCategoryDao;
	
	@Override
	public GoodsCategory save(GoodsCategory obj) {
		try {
			goodsCategoryDao.save(obj);
		} catch (Exception e) {
			throw new ServiceException("添加商品类别发生错误！", e);
		}
		return obj;
	}

	@Override
	public void delete(long id) {
		try {
			goodsCategoryDao.delete(id);
		} catch (Exception e) {
			throw new ServiceException("删除商品类别发生错误", e);
		}
	}

	@Override
	public void update(GoodsCategory obj) {
		try {
			goodsCategoryDao.update(obj);
		} catch (Exception e) {
			throw new ServiceException("更新商品类别发生错误！", e);
		}
	}

	@Override
	public GoodsCategory get(long id) {
		return goodsCategoryDao.get(id);
	}

	@Override
	public List<GoodsCategory> list() {
		return goodsCategoryDao.list();
	}

	@Override
	public List<GoodsCategory> listByPage(int offset, int limit) {
		return goodsCategoryDao.listByPage(offset, limit);
	}

	@Override
	public List<GoodsCategory> find(Map<String, Object> parameter) {
		return goodsCategoryDao.find(parameter);
	}

	@Override
	public List<GoodsCategory> findByPage(Map<String, Object> parameter,
			int offset, int limit) {
		return goodsCategoryDao.findByPage(parameter, offset, limit);
	}

	@Override
	public List<GoodsCategory> search(Map<String, Object> parameter,
			int offset, int limit) {
		return goodsCategoryDao.search(parameter, offset, limit);
	}

	@Override
	public int count() {
		return goodsCategoryDao.count();
	}

	@Override
	public int countByKeyWord(Map<String, Object> parameter) {
		return goodsCategoryDao.countByKeyWord(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return goodsCategoryDao.count(parameter);
	}

	public void setGoodsCategoryDao(GoodsCategoryDao goodsCategoryDao) {
		this.goodsCategoryDao = goodsCategoryDao;
	}

	@Override
	public boolean checkCategoryName(String categoryName) {
		return goodsCategoryDao.countByCategoryName(categoryName)>0;
	}


}
